/*
 * Copyright (C) 2017 The MoonLake Authors
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


package com.minecraft.moonlake.legendaryweaponrel.weapons.tool;

import com.minecraft.moonlake.legendaryweaponrel.weapons.WeaponAbstractPlayerInteract;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

public class Sacrificial extends WeaponAbstractPlayerInteract {

    public Sacrificial() {
        super("sacrificial", "&b牺牲剑", Material.WOOD_SWORD);
    }

    @Override
    public String[] getLore() {
        return new String[] {
                "&7右键后牺牲自身的生命给予周围",
                "&7半径 &a3 &7内的玩家&a力量1 15s &7效果"
        };
    }

    @Override
    protected void onInteract(PlayerInteractEvent event, Player player) {
        // 右键后直接牺牲
        player.setHealth(0d);
        // 获取玩家附近半径 3 内的实体
        player.getNearbyEntities(3d, 3d, 3d).parallelStream()
                // 筛选实体是玩家并且不是自己
                .filter(entity -> entity instanceof Player && !((Player) entity).equals(player))
                .forEach(entity -> {
                    // 则播放声音效果并给予力量效果
                    ((Player) entity).playSound(entity.getLocation(), Sound.BURP, 10f, 1f);
                    ((Player) entity).addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 15 * 20, 0));
                });
    }
}
